home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Instrumentation SDK / Documentation / Sample Code / SampleHistogram.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-19  |  1.4 KB  |  59 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    This code illustrates how to create histogram and split histogram 
  3.  *    statistic nodes and how to update their values.
  4.  */
  5.  
  6. #include "Instrumentation.h"
  7.  
  8. #include <QuickDraw.h>
  9.  
  10.  
  11. OSStatus    InitInstrumentation( void);
  12. void        UpdateStatistics( SInt32 inputValue);
  13.  
  14. InstHistogramClassRef        gInputProfile;
  15. InstSplitHistogramClassRef    gLowInputProfile;
  16.  
  17.  
  18. void        main()
  19. {
  20. OSStatus        err;
  21. int                i;
  22.  
  23.     if ( noErr == ( err = InitInstrumentation()))
  24.     {
  25.         for ( i=0; i < 100; i++)
  26.             UpdateStatistics( Random() % 100);
  27.     }
  28. }
  29.  
  30.  
  31. OSStatus    InitInstrumentation( void)
  32. /* Create and enable our statistics nodes. The counts are initially zero. */
  33. {
  34. OSStatus        err;
  35.  
  36.     // The first histogram will have 20 buckets evenly distributed from 0-100.
  37.     err = InstCreateHistogramClass( kInstRootClassRef, "Samples:Input Values", 
  38.                                     0, 100, 20, kInstEnableClassMask, &gInputProfile);
  39.  
  40.     // Our second histogram will cover the same range, but "zoom in" on the values 0-10.
  41.     if ( noErr == err)
  42.         err = InstCreateSplitHistogramClass( kInstRootClassRef, "Samples:Low Input Values", 
  43.                                                 0, 10, 11, 100, 9, kInstEnableClassMask, 
  44.                                                 &gLowInputProfile);
  45.     return err;
  46. }
  47.  
  48.  
  49. void        UpdateStatistics( SInt32 inputValue)
  50. /* Update the statistics with some new values. */
  51. {
  52.     // Use the same call to update both types of histograms.
  53.     InstUpdateHistogram( gInputProfile, inputValue, 1);
  54.  
  55.     InstUpdateHistogram( gLowInputProfile, inputValue, 1);
  56. }
  57.  
  58.  
  59.